﻿Imports BusinessRule.IBusiness
Imports BusinessRule.BusinessFactory
Imports DatabaseAccess.DBUtility

Partial Class GetTemplateInfo_ascx
    Inherits System.Web.UI.UserControl
    Private m_CommonObj As uLMSCommonIBusiness = uMESBusinessFactory.instance.GetuLMSCommonObject()
    '消息提示
    Private v_Message As String
    '选择件号的下拉列表
    Private v_Index As String
    '选择件号的名称
    Private v_Templateext As String
    '选择件号的值
    Private v_TemplateValue As String
    'ddlTemplate是否显示
    Private v_Visable As Boolean

    '查询和关闭查询图表url
    Private search_rul As String = "~/images/search.gif"
    Private close_rul As String = "~/images/closeMod.png"

    '传给ddlTemplate的资源表
    Private v_ddlTemplate_dt As DataTable

    '控件的下拉列表
    Private v_ddlDropList As Camstar.WebClient.FormsBuilder.WebControls.DropDownList

    '''声明选择件号事件
    Public Event DDlTemplateDataChanged()
    Sub DDlTemplateDataChangedCauseEvent()
        ' Raise an event.
        RaiseEvent DDlTemplateDataChanged()
    End Sub

    '''声明查询件号事件
    Public Event GetTemplateData()
    Sub GetTemplateDataCauseEvent()
        ' Raise an event.
        RaiseEvent GetTemplateData()
    End Sub

    ''' <summary>
    ''' 执行点击查询
    ''' </summary>
    ''' <remarks></remarks>
    Sub DoSearchTemplateInfo()
        SearchTemplate(0)
    End Sub

    ''' <summary>
    ''' 获取下拉列表资源表
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property GetddlTemplateResoucedt() As DataTable
        Get
            Return v_ddlTemplate_dt
        End Get
        Set(ByVal value As DataTable)
            v_ddlTemplate_dt = value
        End Set
    End Property

    ''' <summary>
    ''' 给下拉列表增加属性
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property GetTemplateDDL() As Camstar.WebClient.FormsBuilder.WebControls.DropDownList
        Get
            Return ddlTemplate
        End Get
    End Property

    Public ReadOnly Property GetTemplateNameOrTypeText As Camstar.WebClient.FormsBuilder.WebControls.TextBox
        Get
            Return TemplateName
        End Get
    End Property

    '获取绑定下拉列表值事件
    Sub GetTemplateDataBindCauseEvent()
        TemplateName.Visible = False
        ddlTemplate.Visible = True
        'btnTemplate.Text = "<"
        btnTemplate.ImageUrl = close_rul
        Dim dt As DataTable = GetddlTemplateResoucedt
        ddlTemplate.DropDownControl.Items.Clear()
        ddlTemplate.DropDownControl.DataTextField = "TEMPLATENAME"
        ddlTemplate.DropDownControl.DataValueField = "ID"
        ddlTemplate.DropDownControl.DataSource = dt
        ddlTemplate.DataBind()
        ddlTemplate.DropDownControl.Items.Insert(0, "")
        If (dt.Rows.Count > 0) And (Not IsDBNull(dt.Rows(0)("ID"))) Then
            ddlTemplate.DropDownControl.SelectedValue = dt.Rows(0)("ID")
        End If
    End Sub

    ''' <summary>
    ''' 初始化控件
    ''' </summary>
    ''' <remarks></remarks>
    Sub ClearControl()
        TemplateName.Visible = True
        ddlTemplate.Visible = False
        'btnTemplate.Text = ">"
        btnTemplate.ImageUrl = search_rul
        TemplateName.ClearData()
    End Sub

    ''' <summary>
    ''' 消息提示
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Message() As String
        Get
            Return v_Message
        End Get
    End Property

    ''' <summary>
    ''' 选择件号的文本
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Templateext() As String
        Get
            Return ddlTemplate.DropDownControl.SelectedItem.Text
        End Get
    End Property

    ''' <summary>
    ''' 获取输入的查询条件值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property GetScanProducNameOrTypeText() As String
        Get
            Return TemplateName.TextControl.Text
        End Get
    End Property

    ''' <summary>
    ''' 选择件号的值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property TemplateValue() As String
        Get
            Return ddlTemplate.DropDownControl.SelectedValue
        End Get
    End Property

    ''' <summary>
    ''' 选择件号的索引列值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Index() As Integer
        Get
            Return ddlTemplate.DropDownControl.SelectedIndex
        End Get
    End Property

    ''' <summary>
    ''' 件号下拉列表控件是否显示
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property DDLTemplateVisable() As Boolean
        Get
            Return ddlTemplate.Visible
        End Get
    End Property

    ''' <summary>
    ''' 恢复控件默认显示样式 add YangJiang 20180726
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property InitControl_() As Boolean
        Get
            Return InitControl()
        End Get
    End Property

    Protected Sub btnTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTemplate.Click
        Try
            v_Message = ""
            If Not SearchTemplate(0) Then
                v_Message = "没有查询到模板信息"
            End If
            GetTemplateDataCauseEvent()
        Catch ex As Exception
            v_Message = ex.Message
            GetTemplateDataCauseEvent()
        End Try
    End Sub

    Protected Sub ddlTemplate_DataChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTemplate.DataChanged
        Try
            v_Message = ""
            DDlTemplateDataChangedCauseEvent()
        Catch ex As Exception
            v_Message = ex.Message
            DDlTemplateDataChangedCauseEvent()
        End Try
    End Sub

    ''' <summary>
    ''' 查询件号信息
    ''' </summary>
    ''' <param name="value">0 按钮‘>’查询 1查询按钮直接查询</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function SearchTemplate(ByVal value As Integer) As Boolean
        SearchTemplate = False
        'If btnTemplate.Text = ">" Or value = 1 Then
        If btnTemplate.ImageUrl.Contains("search") Or value = 1 Then
            Dim Templatedt As DataTable = DatabaseHelper.Query_ReturnDatTable(String.Format("select ASSEMWORKFLOWTEMPLATEID ID,TEMPLATENAME from AssemWorkFlowTemplate where TEMPLATENAME like'%{0}%'", TemplateName.TextControl.Text.Trim()))
            'm_CommonObj.GetTemplateInfoLikeNameOrREVISION(TemplateName.TextControl.Text.Trim())
            If Templatedt.Rows.Count = 0 Then
                Exit Function
            End If
            ddlTemplate.DropDownControl.DataTextField = "TEMPLATENAME"
            ddlTemplate.DropDownControl.DataValueField = "ID"
            ddlTemplate.DropDownControl.DataSource = Templatedt
            ddlTemplate.DropDownControl.DataBind()
            'btnTemplate.Text = "<"
            btnTemplate.ImageUrl = close_rul
            ddlTemplate.Visible = True
            TemplateName.Visible = False
            ddlTemplate.DropDownControl.Items.Insert(0, "")
            v_Visable = True
        ElseIf btnTemplate.ImageUrl.Contains("closeMod") Then
            'ElseIf btnTemplate.Text = "<" Then
            'btnTemplate.Text = ">"
            btnTemplate.ImageUrl = search_rul
            ddlTemplate.Visible = False
            TemplateName.Visible = True
            ddlTemplate.DropDownControl.Items.Clear()
            v_Visable = False
        End If
        SearchTemplate = True
    End Function

    ''' <summary>
    ''' 直接查询件号
    ''' </summary>
    ''' <remarks></remarks>
    Sub DirectSerachTemplate()
        If Not String.IsNullOrWhiteSpace(TemplateName.TextControl.Text.Trim()) Or ddlTemplate.Visible Then
            SearchTemplate(1)
            Dim mrcount As Integer = 0 '默认次数
            Dim index As Integer = 0
            For Each item As ListItem In ddlTemplate.DropDownControl.Items
                index += 1
                If item.Text.Contains("默认") Then
                    ddlTemplate.DropDownControl.SelectedValue = item.Value
                    mrcount += 1
                End If
            Next
            'Modify by YangJiang 20180613
            If index > 0 Then
                If mrcount > 1 Then
                    ddlTemplate.DropDownControl.SelectedIndex = 0
                Else
                    ddlTemplate.Visible = True
                    TemplateName.Visible = False
                End If
            Else
                ddlTemplate.Visible = False
                TemplateName.Visible = True
            End If
        End If
    End Sub


    ''' <summary>
    ''' 初始化控件显示样式 add YangJiang 20180726
    ''' </summary>
    ''' <remarks></remarks>
    Function InitControl() As Boolean
        btnTemplate.ImageUrl = search_rul
        ddlTemplate.Visible = False
        TemplateName.Visible = True
        ddlTemplate.DropDownControl.Items.Clear()
        v_Visable = False
        m_UserInfo = Session("CurrentUserInfo")
        Return True
    End Function

    Private m_UserInfo As New BusinessRule.DTO.CurrentUserInfo

End Class
